<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>case title add</title>
    <style>
        table{border-collapse:collapse;border-spacing:0;border-left:1px solid #888;border-top:1px solid #888;margin: auto}
        th,td{border-right:1px solid #888;border-bottom:1px solid #888;padding:5px 15px;}
        th{font-weight:bold;}
        body{text-align: center}
    </style>
    {% load static %}
    <script type='text/javascript' src="/static/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/js/user.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("input[name='addCaseTitle']").click(function(){
                var title = $("#title").val();
                if(title == ''){
                    alert('请输入要添加的case title');
                    return false;
                }
                $("#addCaseTitleForm").submit();
            });

            $("input[name='changeName']").click(function(){
                $(this).parent().parent().find("td:first").find("input").show();
                $(this).parent().parent().find("td:first").find("label").hide();
                $(this).hide();
                $(this).next().show();
            });

            $("input[name='toChangeName']").click(function(){
                var id = $(this).parent().parent().find("td:first").find("input").attr("id");
                var newTitle = $(this).parent().parent().find("td:first").find("input").val();
                var crf = $("input[name='csrfmiddlewaretoken']").val();
                $.ajax({
                    url:'/modifyCaseTitle/',
                    type:'POST',
                    data:{caseId:id,caseTitle:newTitle,csrfmiddlewaretoken:crf},
                    success:function(data){
                        if(data=='1'){
                            alert('操作成功');
                            location.reload();
                        }else{
                            alert('操作失败');
                            location.reload();
                        }
                    }
                });
            });

            $("input[name='addDetail']").click(function(){
                var id = $(this).parent().parent().find("td:first").find("input").attr("id");
                $("input[name='caseId']").val(id);
                $("form[name='addCaseDetailPage']").submit();
            });

            $("input[name='checkCaseContent']").click(function(){
                var id = $(this).parent().parent().find("td:first").find("input").attr("id");
                $("input[name='caseId']").val(id);
                $("form[name='addCaseDetailPage']").attr("action","/checkCaseDetail/");
                $("form[name='addCaseDetailPage']").submit();
            });

            $("input[name='checkCaseDetailName']").click(function(){
                var id = $(this).parent().parent().find("td:first").find("input").attr("id");
                $("input[name='caseId']").val(id);
                $("form[name='addCaseDetailPage']").attr("action","/checkCaseDetailName/");
                $("form[name='addCaseDetailPage']").submit();
            });

            $("input[name='changePosition']").click(function(){
                var position = $(this).parent().prev().find("input").val();
                var id = $(this).parent().parent().find("td:first").find("input").attr("id");
                var crf = $("input[name='csrfmiddlewaretoken']").val();
                $.ajax({
                    url:'/changePosition/',
                    type:'POST',
                    data:{position:position,caseId:id,csrfmiddlewaretoken:crf},
                    success:function(data){
                        if(data == '1'){
                            alert('修改成功');
                            window.location.reload();
                        }else{
                            alert('修改失败');
                            window.location.reload();
                        }
                    }
                });
            });
        });
    </script>
</head>
<body>
<div style="width: 80%;height:40px;background-color: aqua;margin: 0 auto ">
    <div style="float:left;margin-left: 10px;margin-top: 10px"><a href="#" name="projectManager">项目管理&nbsp;&nbsp;</a>|</div>
    <div style="float:left;margin-left: 10px;margin-top: 10px"><a href="#" name="testCaseManager">测试用例管理&nbsp;&nbsp;</a>|</div>
    <div style="float:left;margin-left: 10px;margin-top: 10px"><a href="#" name="bugCheck">bug情况查看&nbsp;&nbsp;</a>|</div>
    <div style="float:left;margin-left: 10px;margin-top: 10px"><a href="#" name="registerPage">注册新用户</a></div>
    <div style="float:right;margin-right:10px;margin-top: 10px"><a href="#" name="logout">退出</a></div>
    <div style="float:right;margin-right:10px;margin-top: 10px">登录人：{{ request.session.showName }}&nbsp;&nbsp;</div>
    <form method="post" name="dataForm">
        {% csrf_token %}
        <input type="hidden" name="dataInput" />
    </form>
</div><p></p>
    <table>
        <tr>
        <form method="post" action="/addCaseTitle/" name="addCaseTitleForm" id="addCaseTitleForm">
            {% csrf_token %}
            <td>位置</td>
            <td width="30px"><input name="position" id="position" size="1px" value="1"/></td>
            <td>cese title</td>
            <td width="300px"><input name="title" id="title" maxlength="200" size="50px"/></td>
            <td><input type="button" name="addCaseTitle" value="确定"/></td>
        </form>
        </tr>
    </table><p>
    <table>
        <tr>
            <td colspan="4" width="530px">测试用例列表</td>
        </tr>
        {% for caseInfo in caseInfos %}
        <tr>
            <td>{{ forloop.counter }}
            <input size="30px" value="{{ caseInfo.caseTitle }}" style="display: none" id="{{ caseInfo.id }}"/>
            </td>
            <td style="text-align: left">
                <label name="titleLabel">{{ caseInfo.caseTitle }}</label>
            </td>
            <td>
                <input size="1px" value="{{ caseInfo.position }}" name="positionChange"/>
            </td>
            <td width="350px">
                <input type="button" name="changeName" value="修改名字"/>
                <input type="button" name="toChangeName" value="提交修改" style="display: none"/>
                <input type="button" name="addDetail" value="添加case"/>
                <input type="button" name="checkCaseDetailName" value="case列表"/>
                <input type="button" name="changePosition" value="更改位置"/>
            </td>
        </tr>
        {% endfor %}
    </table>
    <form method="post" action="/addCaseDetailPage/" name="addCaseDetailPage">
    {% csrf_token %}
        <input type="hidden" name="caseId" />
    </form>
</body>
</html>